package com.example.springboot.service.Impl;

import com.example.springboot.entity.Note;
import com.example.springboot.mapper.NoteMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteService {

    private final NoteMapper noteMapper;

    public NoteService(NoteMapper noteMapper) {
        this.noteMapper = noteMapper;
    }

    public Note getNoteById(Integer id) {
        return noteMapper.findById(id);
    }

    public List<Note> getNotesByUserId(Integer userId, int pageNum, int pageSize,Integer importance) {
        pageNum = (pageNum - 1) * pageSize;
        if(importance == -1){
            return noteMapper.findByUserId(userId, pageNum, pageSize);
        }else{
            return noteMapper.findByUserIdAndImportance(userId, pageNum, pageSize,importance);
        }

    }

    public void addNote(Note note) {
        noteMapper.insert(note);
    }

    public void updateNote(Note note) {
        noteMapper.update(note);
    }

    public void deleteNoteById(Integer id) {
        noteMapper.delete(id);
    }
}
